/**
* mpsvr的公用定义
* @author thinkry
*/

#ifndef __MPSVR_DEF_H__
#define __MPSVR_DEF_H__

#include "CTBase.h"
#include "CTBuffer.h"
#include "CTStat.h"
#include "CTSizeString.h"
#include "CTArray.h"
#include "CTObjectMgr.h"
#include "CTShmQueue.h"
#include "net/CTEpoll.h"
#include "CTMsgBase.h"
#include "CTConfig.h"
#include "CTServerUtils.h"
#include "CTHashObjectMgr.h"

using namespace CTLib;

//===============================================
// 

// 相关文件的定义，做为一个约定，不用在配置文件中读取
#define APPNAME             "mpsvr"
#define FILE_CONFIG         "../config/" APPNAME ".conf"
#define FILE_NORMALLOG      "../log/" APPNAME ".log"
#define FILE_ERRORLOG       "../log/" APPNAME ".err"
#define FILE_STATLOG        "../log/" APPNAME ".sta"
#define FILE_PIDFILE        "../bin/" APPNAME ".pid"
#define FILE_SO             "../bin/main.so"

#define CHECK_RETURN(iRet)  do { if (iRet) { return iRet; } } while(0)
#define CHECK_EXIT(iRet) do { if (iRet) { exit(iRet); } } while(0)
#define CHECK_THROW(iRet) do { if (iRet) { CT_THROW((iRet)); } } while(0)

//===============================================
// 这两个定义是为了能够在Windows下编译
#ifdef WIN32
    #define fork()   (1)
    #define getopt(argc, argv, optstring) (0)
    #define signal(signum, handler) (0)

    #define SIGUSR1 10
    #define SIGUSR2 12
    #define kill(pid, sig) (0)

    #define WNOHANG 1
    #define WUNTRACED 2
    #define waitpid(pid, status, options) (0)
#else
    #include <sys/types.h>
    #include <signal.h>
    #include <sys/wait.h>
#endif

//===============================================
// 统计项的定义

// 统计的CTLog
#define CT_STAT (CTLib::CTSingleton<CTLib::CTLog, 2>::Instance())

/**
* 统计项
*/
enum EMpStat
{
    mp_stat_recvpkg = 0,
    mp_stat_sendpkg,
    mp_stat_recvmsg,
    mp_stat_sendmsg,
    mp_stat_accept, 
    mp_stat_no_idle_client,
    mp_stat_reconnect,
    mp_stat_idleclose,
    mp_stat_mainloop,
    mp_stat_waittimeout,
    mp_stat_check,
};

#endif //__MPSVR_DEF_H__
